package com.bestcem.xm.qdes.service;

import com.alibaba.fastjson.JSONObject;
import com.bestcem.xm.common.core.domain.web.XmResultJson;
import com.bestcem.xm.component.mybatis.service.IXmService;
import com.bestcem.xm.qdes.controller.param.*;
import com.bestcem.xm.qdes.controller.vo.*;
import com.bestcem.xm.qdes.entity.QdesProject;
import com.bestcem.xm.qdes.entity.QdesQstruct;
import com.bestcem.xm.qdes.entity.QdesQuestion;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.collect.Multimap;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

public interface QdesProjectService extends IXmService<QdesProject> {

    /**
     * 获取答卷数
     *
     * @param id id
     * @return 答卷数
     */
    QdesProjectRespNumVo getProjectRespNum(String id);

    /**
     * 修改标题
     *
     * @param id    id
     * @param title title
     */
    void updateProjectTitle(String id, String title);

    /**
     * 修改是否阅读
     *
     * @param id    id
     * @param param param
     */
    void updateProjectRead(String id, ProjectReadParam param);

    /**
     * 修改所属文件夹
     *
     * @param id    id
     * @param param param
     */
    void updateProjectFolder(String id, ProjectFolderIdParam param);

    /**
     * 创建项目
     *
     * @param param param
     */
    QdesProjectVo createProject(ProjectCreateParam param);

    /**
     * 删除项目
     *
     * @param param param
     */
    QdesProjectDeleteVo deleteProject(ProjectDeleteParam param);

    /**
     * 删除项目
     *
     * @param param param
     */
    void finishProject(ProjectFinishParam param);

    /**
     * 获取项目详情
     *
     * @param id     id
     * @param userId userId
     * @param orgId  orgId
     * @return 数据
     */
    QdesProjectDetailVo getProjectDetail(String id, String userId, String orgId);

    /**
     * 获取当前问卷的可设置配额的题目列表
     *
     * @param id    id
     * @param param param
     * @return 数据
     */
    List<JSONObject> getProjectQuestions(String id, ProjectQuestionParam param);

    /**
     * 查询当前问卷问卷端所使用的外部参数
     *
     * @param projectId
     * @return
     */
    XmResultJson<Object> getProjectExtParams(String projectId);

    /**
     * 获取问卷最大gid
     *
     * @param id
     * @return
     */
    Integer getProjectMaxGid(String id);

    /**
     * 更新问卷最大gid
     *
     * @param id
     * @param maxGid
     * @return
     */
    XmResultJson<?> setProjectMaxGid(String id, Integer maxGid);

    List<JSONObject> getReleasedQuestions(QdesProject project, QdesQstruct struct);

    Map<String, Object> releaseProject(QdesProject project, QdesQstruct struct, Boolean force);

    XmResultJson<JSONObject> putAttr(String projectId, JSONObject attrJson) throws IOException;

    /**
     * 导入项目
     *
     * @param param param
     */
    XmResultJson<QdesImportProjectVo> importProject(ProjectImportParam param, MultipartFile file);

    void templateProject(HttpServletResponse response) throws IOException;

    List<JSONObject> walkQstructQuestions(JSONObject data);

    void fillQstructData(QdesQstruct qdesQstruct, List<QdesQuestion> qdesQuestions);

    void readAllProject(String userId, String orgId);

    void resetSeq(JSONObject data);

    JSONObject initWechatQrcode(String id);

    QdesProject getReleasedProject(String projectId, Integer version) throws JsonProcessingException;

    QdesQstruct getQstructByVersion(String projectId, Integer version);

    QdesProject getCurrentProject(String projectId) throws JsonProcessingException;

    JSONObject getProjectOwner(String pid, String uid, String orgId);

    List<JSONObject> getTimeCost(String pid, String gid);

    void postTimeCost(String pid, JSONObject params);

    JSONObject getFinishedRspdCount(String projectId, Integer dataStatus, Integer status);

    Multimap<String, Integer> getFinishedRspdCountV2(String projectId, Integer dataStatus, Integer status);

    QdesProject createOneProject(QdesProject project, boolean forTemplet);

    List<Integer> acquireProjectGid(String projectId, Integer num);

    JSONObject getScoreRange(String projectId, Integer gid);
}
